package
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import flash.utils.getDefinitionByName;
	
	import model.MainModel;

	public class Splash extends MovieClip
	{	
		public static const DOCUMENT_CLASS : String = 'Main';
		private var preloader:PreloaderMc = new PreloaderMc();
		
		public function Splash() {
			stage.showDefaultContextMenu = false;
			stage.scaleMode = "noScale";
			super();
			stop();
			preloader.stop();
			addChild(preloader);
			preloader.x = (stage.stageWidth - preloader.width) * 0.5;
			preloader.y = (stage.stageHeight - preloader.height) * 0.5;
			loaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler, false, 0, true);
			loaderInfo.addEventListener(Event.COMPLETE, init, false, 0, true);
		}
		
		private function progressHandler(event: ProgressEvent) : void {
			var loaded: uint = event.bytesLoaded;
			var total: uint = event.bytesTotal;
			preloader.gotoAndStop(Math.ceil(loaded / total * 100));
		}
		
		private function init(event:Event):void{
			nextFrame();
			removeChild(preloader);
			var vgaleree:Class = Class(getDefinitionByName(DOCUMENT_CLASS));
			if (vgaleree){
				var app: Object = new vgaleree();
				addChildAt(app as DisplayObject  , 0);
			}
		}
		
		
	}
}